package com.wjgl.action;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.opensymphony.xwork2.ActionSupport;
import com.wjgl.domain.User;
import com.wjgl.service.UserService;

public class RegisterAction extends ActionSupport {
	private UserService userService;
	private String name;
	private String email;
	private String password;
	private String password1;
	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getPassword1() {
		return password1;
	}
	public void setPassword1(String password1) {
		this.password1 = password1;
	}
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		if(!password.equals(password1))
			return INPUT;
		User user = new User();
		user.setName(name);
		user.setEmail(email);
		user.setPassword(password);
		user.setState((short)0);
		user.setIsadmin((short)0);
		
		Date date = new Date();
		//System.out.println(date);
		SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = df1.format(date);
		//System.out.println(time);
		user.setRegisterdate(Timestamp.valueOf(time));
		
		userService.register(user);
		return SUCCESS;
	}
	
	
}
